package com.mt.grand.singleton.reflect;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

/**
 * 反射对单例的侵入以及如何防止这种侵入
 */
public class ReflectSingletonTest {

    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchMethodException, InvocationTargetException {

        ReflectSingleton reflectSingleton1 = ReflectSingleton.getInstance();

        Class<ReflectSingleton> aClass = ReflectSingleton.class;

        Constructor<ReflectSingleton> constructor = aClass.getDeclaredConstructor();
        constructor.setAccessible(true);
        ReflectSingleton reflectSingleton2 = constructor.newInstance(null);

        System.out.println(reflectSingleton1==reflectSingleton2);
    }
}